package com.example.unisys.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.unisys.dao.CourseMapper;
import com.example.unisys.entity.Course;
//import com.example.unisys.dao.baseMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class CourseService extends ServiceImpl<CourseMapper,Course> {


    public int insert(Course course) {
        return baseMapper.insert(course);
    }



    public int update(Course course) {
        return baseMapper.update(course,new QueryWrapper<Course>().lambda().eq(Course::getCourse_id,course.getCourse_id()));
    }


    public List<Course> getAllCourse(int start, int pagesize) {
        return baseMapper.getAllCourse(start, pagesize);
    }


    public List<Course> getValidCourse(int start, int pagesize) {
        return baseMapper.getValidCourse(start, pagesize);
    }

    public Integer getValidCourseSum() {
        return baseMapper.getValidCourseSum();
    }


    public List<Course> getMainCourseBySearch(Map<String, Object> hs1) {
        return baseMapper.getMainCourseBySearch(hs1);
    }

    public List<Course> getAllRepoCourses(HashMap<String, Object> hs) {
        return baseMapper.getAllRepoCourses(hs);
    }

    public int getRepoCourseSum() {
        return baseMapper.selectCount(new QueryWrapper<>());
    }


    public boolean isPublishable(Course course) {
       return baseMapper.isPublishable(course)==5;
    }

}
